<?php
defined('TWITTER_DB_DEV_SERVER')|| define('TWITTER_DB_DEV_SERVER',false);
defined('TWITTER_DB_DEV_DEBUG') || define('TWITTER_DB_DEV_DEBUG',false);

defined('TWITTER_MCACHE_EXPIRE_TIME')|| define('TWITTER_MCACHE_EXPIRE_TIME',60*10); //memcache 失效时间
defined('TWITTER_MCACHE_CHANNEL_NAME')|| define('TWITTER_MCACHE_CHANNEL_NAME','twitter'); //memcache分配的频道名
defined('TWITTER_DB_PAGE_SIZE')|| define('TWITTER_DB_PAGE_SIZE',20); //分页每页的大小
defined('PDO_USER_TAGNAME')||define('PDO_USER_TAGNAME','usermood'); //推他用户信息表pdo 的标签号
defined('PDO_MAP_TAGNAME')|| define('PDO_MAP_TAGNAME','mapmood'); //转推索引表pdo 的标签号
defined('PDO_HOT_TAGNAME')|| define('PDO_HOT_TAGNAME','hotmood'); //热门推他表pdo 的标签号

define('CONVEY_EXPIRE_TIME',60); //转发的信息memcache 失效时间
defined('HOT_TWITTER_MCACHE_EXPIRE_TIME')|| define('HOT_TWITTER_MCACHE_EXPIRE_TIME',60*10); //热门记录memcache 
defined('FEED_DELETE_MCACHE_EXPIRE_TIME')|| define('FEED_DELETE_MCACHE_EXPIRE_TIME',60*60*12); //动态删除memcache 
define('HOT_TWITTER_CONVEY_NUM',5); //转发条数限制入热门库
define('HOT_TWITTER_COMMENT_NUM',5); //评论条数限制入热门库
define('NEW_HOT_TWITTER_NUM',5); //每次获取新的随便看看条数

define('PERDAY_TUITA_MAX_NUM',10); //推他勋章规则：每天只能发表10条
defined('PERDAY_TUITA_EXPIRE_TIME')|| define('PERDAY_TUITA_EXPIRE_TIME',60*60*24+60); //memcache 失效时间 一天


class UCConfTwitter
{	
	
	/**
	* 获取某个用户推他首页缓存cache key
	* @param string user_id 
	* @param int limit :每页显示的条数
	* @return string 
	*/
	public static function getMemUserTwitterPage1Key($user_id){
		$mem_key = $user_id.'_moodrecord_list_0_'.TWITTER_DB_PAGE_SIZE;
		return  md5($mem_key);
	}

	/**
	* 获取某个用户推他最新发表的推他缓存cache key
	* @param int type :类型 0全部，1 文字 ，2图片，3 视频
	* @param int limit :每页显示的条数
	* @return string 
	*/
	public static function getMemUserLatestTwitterKey($user_id){
		$mem_key = $user_id.'_latest_moodrecord';
		return  md5($mem_key);
	}

	/**
	* 获取某个用户转推他首页缓存cache key
	* @param string user_id 
	* @param int limit :每页显示的条数
	* @return string 
	*/
	public static function getMemUserConveyTwitterPage1Key($user_id){
		$mem_key = $user_id.'_convey_moodrecord_list_0_'.TWITTER_DB_PAGE_SIZE;
		return  md5($mem_key);
	}

	/**
	* 获取某条推他信息cache key
	* @param string mood_id: 推他的唯一id值
	* @param string user_id: 推他的发表者id值
	* @return string 
	*/
	public static function getMemOneTwitterInfoKey($mood_id,$user_id){
		$mem_key = $mood_id.'_one_mood_info_'.$user_id;
		return  md5($mem_key);
	}
	/**
	* 获取热门推他首页缓存cache key
	* @param int type :类型 0全部，1 文字 ，2图片，3 视频
	* @param int start :起始位置
	* @param int limit :每页显示的条数
	* @return string 
	*/
	public static function getMemHotTwitterPageKey($type,$start,$limit){
		$list_key = 'hot_twitter_list_'.$start.'_'.$limit.'_'.$type;
		return  md5($list_key);
	}

	/**
	* 获取热门推他总数cache key
	*/
	public static function getMemcacheHotTwitterTotalKey($type){
		return  md5("hot_twitter_total_count_".$type);
	}

	/**
	* 获取某条记录是否已经插入hot库
	*/
	public static function getMemTuitaInHotKey($mood_id,$user_id){
		return  md5("mood_id_".$mood_id."in_hot_".$user_id);
	}

	/**
	* 存放转推映射关系
	*/
	public static function getMemConveyTwitterMap($mood_id){
		return  "twitter_map_".$mood_id;
	}

	/**
	* 存放审核信息库删除的记录id：cache key
	*/
	public static function getMemcacheDeleteFeedTwitterKey(){
		return  md5("feed_delete_twitter_id");
	}

	/**
	* 单个用户每天发表的推他数：cache key
	*/
	public static function getMemcacheUserTuitaNumPerdayKey($user_id){
		$day_time = date("Y-m-d",time());
		return  md5($user_id."_TuitaNum_Perday_".$day_time);
	}

}



/**
* 提供统一的DB配置
* @param string $tagname DB的标识符
*/
function twitter2dbconfig($tagname,$key){

	$user        = null;
    $pass        = null;
    $port        = null;
    $table       = null;
    $table_alias = null;
	if(__UC_ENV=='DEV'){
		if($tagname=='usermood'){

			return array(
				'driver' => 'mysql',
				'host' => '10.129.128.14',
				'port' => '3306',
				'username' => 'root',
				'password' => '123qwe',
				'database' => 'd_twitter',
				'table' => 't_twitter_user'
			);
		}else if($tagname=='tagmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.129.128.14',
				'port' => '3306',
				'username' => 'root',
				'password' => '123qwe',
				'database' => 'd_twitter',
				'table' => 't_twitter_tag'
			);
		}else if($tagname=='hotmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.129.128.14',
				'port' => '3306',
				'username' => 'root',
				'password' => '123qwe',
				'database' => 'd_twitter',
				'table' => 't_twitter_hot'
			);
		}else if($tagname=='mapmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.129.128.14',
				'port' => '3306',
				'username' => 'root',
				'password' => '123qwe',
				'database' => 'd_twitter',
				'table' => 't_twitter_map'
			);
		}
		
	}else if(__UC_ENV=='TEST'){
		if($tagname=='usermood'){

			return array(
				'driver' => 'mysql',
				'host' => '10.10.85.4',
				'port' => '8066',
				'username' => 'ucdbuser',
				'password' => 'sdf2w@!w',
				'database' => 'd_twitter',
				'table' => 't_twitter_user'
			);
		}else if($tagname=='hotmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.10.85.4',
				'port' => '8066',
				'username' => 'ucdbuser',
				'password' => 'sdf2w@!w',
				'database' => 'd_twitter',
				'table' => 't_twitter_hot'
			);
		}else if($tagname=='mapmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.10.85.4',
				'port' => '8066',
				'username' => 'ucdbuser',
				'password' => 'sdf2w@!w',
				'database' => 'd_twitter',
				'table' => 't_twitter_map'
			);
		}
		
	}else{
		if($tagname=='usermood'){

			return array(
				'driver' => 'mysql',
				'host' => '10.150.9.5',
				'port' => '8066',
				'username' => 'ucdbuser',
				'password' => '(qnO-ps:Oi^0F0',
				'database' => 'd_twitter',
				'table' => 't_twitter_user'
			);
		}else if($tagname=='hotmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.150.9.5',
				'port' => '8066',
				'username' => 'ucdbuser',
				'password' => '(qnO-ps:Oi^0F0',
				'database' => 'd_twitter',
				'table' => 't_twitter_hot'
			);
		}else if($tagname=='mapmood'){
			return array(
				'driver' => 'mysql',
				'host' => '10.150.9.5',
				'port' => '8066',
				'username' => 'ucdbuser',
				'password' => '(qnO-ps:Oi^0F0',
				'database' => 'd_twitter',
				'table' => 't_twitter_map'
			);
		}
	}
}